import { DEV } from "../config/config"
export default {
    async get(url, params) {
        try {
            const queryString = params? Object.entries(params).map(([key, value]) => `${key}=${value}`).join('&') : ""
            return await (await fetch(`${DEV ? '/api' : ''}${url}?${queryString}`,{
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json',
                },
            })).json()
        } catch (err) {
            return  err
        }
    },
    async post(url, body) {
        try {
            return await (await fetch(`${DEV ? '/api' : ''}${url}`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(body),
            })).json()
        } catch (err) {
            return err
        }
    }
}